;;;   使用方法:
;;;         具体操作: 先 M-: ,  再输入
;;;         (load "..../test.el")
;;;
;;;    确认命令接受开启,
;;;    确认发送的地址, 端口 正确
;;;    <f12> 就可以发送找到的命令 ,
;;;      形如: (%%  ......  %%)
;;;

;;; todo: 
;[Lz1CEOcRr12nC4lfDA7l] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf1dab698b-600b-40dd-b580-dc0d83eedb46</func-param-1><func-param-2>./candev/plugin/emacs/local-todo.can</func-param-2></do-func><cmd-end/>%%)












;[bPN2B14DgnsF4zWGhcw9] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf9df1842c-e893-4279-abf2-7de0fcb9016e</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
;;;简略原理



;[wxH2wE2Ns1UIM7VuXvRT] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf7d47fb56-4303-45b5-9cfd-d99592e65a50</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)

(setq  myproc nil) ;全局变量初始化
(setq  root-path nil) 
(setq  myproc-name "1234jfy")
(setq  host-address "127.0.0.1")
(setq  host-port    "27193")
(setq  cmd-max-len  5120)
(setq  random-string-length 20)
;;这个用来把 f11 f12 定义为 jjump的快捷键
(global-set-key (kbd "<f11>") 'jjump-head ); f11 f12 功能一样,唯一区别是最后光标停留的位置不同,一个是头一个是尾
(global-set-key (kbd "<f12>") 'jjump-tail );[Hwt1V5nHkleqQ77SGTNH] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfd4ae12b8-addc-47b0-b32a-82d83572ba2c</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
(setq fff 'jjump)
(global-set-key (kbd "<f9>") 'jjump-file-src ); 
(global-set-key (kbd "<f8>") 'create-emacs-can-links);[9INakP7CaN9RRyghmsYD] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfca9a24aa-0023-4355-b2dd-7786419d721a</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
(setq char-set "0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ")
(setq char-set-len (length char-set))

;[xkkVYN2rrG4kgNIVN5Gv] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfff7b03a4-1303-40fe-9ea5-f57584c79f53</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
 (setq part1 "<cmd-end/>
<cmd-start/>

<set-target-canvas>
<canvas-filename>CURRENT-CANVAS</canvas-filename>
</set-target-canvas>
<网络文件独占模式>
 <action--drop-package 
		       parent-uid = \"FIRST-CHOOSED\" 
                       x=\"500\" y =\"400\"  
		       XY-确定方法 = \"FIRST-CHOOSED > RIGHT-TOP > 0 > 0\"
                       flags = \"x-y-is-canvas-coordinate\"
                       filename=\"./package/000/pkg/src-location.better.pkg\" start-pos=\"48\" 
                       />
<sequence-operation-on-package>
     <package-uid>CREATED-JUST-NOW</package-uid> 

<port-index> 4  </port-index>   <port-value>")

  (setq part2 "</port-value> <port-index> 5  </port-index>   <port-value>")
  
  (setq part3 "</port-value>")


  (setq part4 "<package-uid>FIRST-CHOOSED</package-uid>
<get-package-or-jci-include-self/>
<发送canvas定位xml命令>
      <文件类型>")

  (setq part5 "</文件类型>")

  (setq part6 "</发送canvas定位xml命令>
</sequence-operation-on-package >
</网络文件独占模式>
<cmd-end/>   ")


	  (setq part-a "[")
	  (setq part-b "]")


(setq relative-path-1 "/home/guest/qbs/")
(setq relative-path-2 "~/guest/qbs/")



(setq tt134 (getenv "QBS_INSTALL_PATH_1"))
(if (stringp tt134)
    (if  (> (length tt134) 1)
	(setq relative-path-1 tt134)
      )
  )
(setq tt134 (getenv "QBS_INSTALL_PATH_2"))
(if (stringp tt134)
    (if  (> (length tt134) 1)
	(setq relative-path-2 tt134)
      )
  )



(setq relative-path-1-len (length relative-path-1))
(setq relative-path-2-len (length relative-path-2))


;[GFq0975z4YQX7c7GC83y] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf4a34adba-5b16-45ae-a1df-66f5bf13e141</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
(defun myfilter (proc string)
  ""
  ;;(current-buffer)
  ;;
  ;;(with-current-buffer (process-buffer proc)
  ;;  (insert string)
  ;;  )
  (insert string)
  (forward-char 3)
  )

(defun jjump-head ()
  "-----"
   (interactive)
  (funcall fff "head")
  (princ "==head===\n");
  )
(defun jjump-tail ()
  (interactive)
  (funcall fff "tail")
  (princ "==tail===\n");
  )
;[g7ffowhwMeEBGzN8cYAd] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfe9e93d38-434c-4452-a01f-6eb454e02a9b</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
(defun jjump (set-curse-pos )
  "注意   (%%   %%)  不能嵌套! 
  global myproc
"
  (interactive)
  ;;(backward-word)
  ;;(setq cur-char (string (following-char)))
  (setq backup-pos (point))
  
  (let (default-forward-limit default-backward-limit start-id end-id start-id-len end-id-len )
    (setq start-id "(%%")
    (setq end-id "%%)")
    
    (setq default-forward-limit 2048)
    (setq default-backward-limit 2048)
    (setq start-id-len (length start-id))
    (setq end-id-len (length end-id))
    (let (min_pos  max_pos cur-pos  forward-limit  backward-limit  forward-limit-max  backward-limit-max
		   start-id-pos  end-id-pos  range-pos1 range-pos2	continue-work   )
      ;;
      ;;
      ;;
      ;;
      ;;__________________________________________________________________________________________________________
      ;;^min_pos                                                   ^cur-pos                                      ^max_pos
      ;;<-----                     backward-limit-max          ---><--- forward-limit-max                     -->
      ;;                                         range-pos1^                ^range-pos2
      ;;
      ;;                                                                   forward-limit为forward-limit-max和default-forward-limit的最小直
      ;;  backward-limit为 (min  backward-limit-max and default-backward-limit)
      ;;
      ;;
      ;;
      ;;
      
      (setq continue-work 0)
      (setq min_pos (point-min))
      (setq max_pos (point-max))
      (setq cur-pos (point))
      ;; forward-limit-max 是长度, 不是位置
      ;; backward-limit-max 是长度, 不是位置
      (setq forward-limit-max (- max_pos cur-pos))
      (setq backward-limit-max (-  cur-pos min_pos))
      (if (> forward-limit-max default-forward-limit)
	  (progn ; true
	    (setq forward-limit default-forward-limit)
	    )
	(progn ; else
	  (setq forward-limit (- forward-limit-max 0))
	  )
	)
      (if (> backward-limit-max default-backward-limit)
	  (progn ; true
	    (setq backward-limit default-backward-limit)
	    )
	(progn ; else
	  (setq backward-limit backward-limit-max)
	  )
	)
      ;;range-pos1 range-pos2 是位置, 不是长度
      (setq range-pos1  (+ (- cur-pos start-id-len) 1))
      (setq range-pos2  (- (+ cur-pos start-id-len) 1))
      (princ (format "000 前向找 start-id  %d  %d  %d  \n" range-pos1 range-pos2 cur-pos));
      (if ( < range-pos1 (- cur-pos backward-limit)) 
	  (progn
	    (setq range-pos1  (- cur-pos backward-limit)   )
	    )
	)
      (if (> range-pos2 (+ cur-pos forward-limit) )
	  (progn
	    (setq range-pos2 (+ cur-pos forward-limit))
	    )
	)
      
      ( goto-char range-pos1 )
      (princ (format "111 前向找 start-id  %d  %d  %d  \n" range-pos1 range-pos2 (point)));
      ;[t8mtni2MPELPpHb749Sg] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfca0f2a81-67e5-425d-9248-823fbd1576a3</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
      (setq temp-pos1 (search-forward start-id range-pos2 t 1))
      (if temp-pos1
	  (progn
	    ;;找到了start-id
	    (princ "111 前向找到了 start-id\n");
	    (setq cur-pos (point))
	    (setq forward-limit-max (- max_pos cur-pos))
	    (setq backward-limit-max (-  cur-pos min_pos))
	    (if (> forward-limit-max default-forward-limit)
		(progn ; true
		  (setq forward-limit default-forward-limit)
		  )
	      (progn ; else
		(setq forward-limit (- forward-limit-max 0))
		)
	      )
	    (if (> backward-limit-max default-backward-limit)
		(progn ; true
		  (setq backward-limit default-backward-limit)
		  )
	      (progn ; else
		(setq backward-limit backward-limit-max)
		)
	      )

	    ;[D6seDnP9kLMVmgUIegsL] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf14522eda-7fef-480b-8421-8b45b9ba09fe</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	    (setq start-id-pos cur-pos)
	    (setq end-id-pos (search-forward end-id (+ cur-pos forward-limit)   t  1))
	    (if   end-id-pos
		(progn ; true
		  ;;得到了 end-id
		  )
	      ) 
	    (setq continue-work 0)
	    )

	(progn
	  ;; 没有找到start-id
	  (princ "111 前向没有找到 start-id\n");
	  ;[HuX9KCARbwEtfTGV1igW] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf332bc8a6-4efa-48c8-a30a-9e972461fa40</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (setq temp-pos2 (search-forward end-id range-pos2 t 1))
	  (if temp-pos2
	      (progn
		;;找到了end-id
		(princ "222 前向找到 end-id\n");
		(setq cur-pos (point))
		(setq forward-limit-max (- max_pos cur-pos))
		(setq backward-limit-max (-  cur-pos min_pos))
		(if (> forward-limit-max default-forward-limit)
		    (progn ; true
		      (setq forward-limit default-forward-limit)
		      )
		  (progn ; else
		    (setq forward-limit (- forward-limit-max 0))
		    )
		  )
		(if (> backward-limit-max default-backward-limit)
		    (progn ; true
		      (setq backward-limit default-backward-limit)
		      )
		  (progn ; else
		    (setq backward-limit backward-limit-max)
		    )
		  )
		(setq end-id-pos cur-pos)
		;[x0GQmt2VErVQ3lnyxELn] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfc8b0f4b9-c560-45fd-a6a9-3f36868cd210</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
		(setq start-id-pos (search-forward start-id (- cur-pos backward-limit)   t  -1))
		(if start-id-pos
		    (progn
		      (princ "333 找到 start-id\n");
		      )
		  (progn
		    (princ "333 没找到 start-id\n");
		    )
		  )

		
		(setq continue-work 0)
		
		)
	    (progn
	      (princ "222 前向没有找到 end-id\n");
	      (setq continue-work 1)
	      )
	    )
	  )
	)
      
      (princ (format "cur-pos is  %d. ( %d %d) forward-----limit is %d  %d\n" cur-pos min_pos max_pos  forward-limit-max backward-limit-max))

      ;[qggyK6pIsmz8WY3gNd0S] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfb97d4604-30f0-41be-8b06-3daa0ae842de</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
      (if (= continue-work 0)
	  (progn
	    
	    
	    )
	(progn
	  ( goto-char backup-pos ) ;恢复原来位置
	  (setq start-id-pos nil)
	  (setq end-id-pos nil)
	    
	    )
	)


;[bywfk6W9KcFYaS1gdhGR] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf851ff698-124c-4e53-aa53-fc566d55b738</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
      (setq cur-pos (point))
      (setq forward-limit-max (- max_pos cur-pos))
      (setq backward-limit-max (-  cur-pos min_pos))

      
      (if (> forward-limit-max default-forward-limit)
	  (progn ; true
	    (setq forward-limit default-forward-limit)
	    )
	(progn ; else
	  (setq forward-limit (- forward-limit-max 0))
	  )
	)
      
      (if (> backward-limit-max default-backward-limit)
	  (progn ; true
	    (setq backward-limit default-backward-limit)
	    )
	(progn ; else
	  (setq backward-limit backward-limit-max)
	  )
	)
      


      
      (if  (= continue-work 1)
	  (progn ; true

	    (princ (format "before searching, mouse pos is  %d.  forward-----limit is %d \n" (point) forward-limit  ))
	    
	    (setq end-id-pos (re-search-forward end-id (+ cur-pos forward-limit)   t  1))
	    (princ (format "after searching, mouse pos is  %d.\n" (point)))
	    (if   end-id-pos
		(progn ; true
		  ;;得到了 end-id
		  (princ "找到了 end-id\n");
		  ( goto-char cur-pos )
		  (setq start-id-pos (re-search-forward start-id (+ cur-pos forward-limit)   t  1))
		  ( if start-id-pos 
		      (progn ; true
			(princ "前向找到了 start-id\n");
			( if  (> start-id-pos end-id-pos)
			    (progn ; true , start 在 end 后面, 不合适
			      (setq start-id-pos nil)
			      )
			  )
			)
		    )
		  ( if start-id-pos
		      (progn ; else
			)
		    (progn ; else
		      ;[e2ROtVpkzCKtx2c72Iuf] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasff7ea48c4-8d33-49da-8710-2f741ab6376e</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
		      (princ "前向没有找到 start-id , 试试后向...\n");
		      ( goto-char cur-pos )
		      (setq start-id-pos (re-search-forward start-id (- cur-pos backward-limit)   t  -1))
					;;( goto-char cur-pos )
		      ( if start-id-pos
			  (progn
			    ;;后向找到了 start-id
			    (setq start-id-pos (+ start-id-pos start-id-len));注意,调整了位置,因为方向不同,光标停留位置不同
			    )
			)
		      )
		    )

		  
		    
		  )
	      (progn ; else
					; 没有得到 end-id
		;[Uqo8i6kC5Skzczfv4qyp] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf8192578d-18aa-491c-948b-b5a6c5fcee99</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
		(princ "没有找到 end-id\n");
		)
	      )
	    ;[16GAFBC9ld6X8zT2Czlu] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf40c10419-f37b-434c-8152-01b80f6a34c2</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	    ( if start-id-pos
		(progn ; true
		  (princ "--找到了 start-id\n");
		  ;; 不要在这里处理结果

		  
		  )
	      (progn ; else
		(princ(format "没有找到需要发送的数据.%s\n" "---" )   )
		)
	      
	      )
	    )
	(progn
	  ;[kbccLHfuR7h8gEEFmbTy] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf4b9cdddb-b3f0-45d5-9ae2-39c1691efca8</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  ;; continue work == 0
	  )
	)
      (princ "111在这里处理结果\n");
      ;[cgfmPf5w44Bq3gc3i6K6] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasffd782346-4dbb-43d9-b543-8c0377c51d4c</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
      ( if (or (eq start-id-pos nil) (eq end-id-pos nil))
	  (progn
	    ;; 没找到
	    (princ "222没找到\n");
	    ( goto-char backup-pos )
	    )
	(progn
	  ;; got, 在这里处理结果
	  (princ "222在这里处理结果\n");
	  (setq start-id-pos (- start-id-pos start-id-len))
	  ;;(setq end-id-pos (- end-id-pos end-id-len))
	  (setq result-string (buffer-substring-no-properties   start-id-pos end-id-pos))
	  (princ(format "---result is: %s\n" result-string))
	  (setq output-string (substring result-string start-id-len (- 0 end-id-len)))

	  ;;process-send-string process string
	  ;[1ytzV0HiYzYf2MiF1zhv] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfdbf1b223-7b59-46a0-945f-9161dc093d70</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (setq need-to-connect 0)
	  (if myproc
	      (progn
		(setq myproc-status (process-status myproc))
		(princ (format "myproc status is :%s\n" myproc-status))
		(if (string= myproc-status "closed")
		    (progn
		      (setq need-to-connect 1)
		      )
		  )
		)
	    (progn
	      (setq need-to-connect 1)
	      )
	    )
	  ;[pEVQHQziGw9uRnPKdVhW] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfd235b163-29a6-4ffe-a705-5d5abcce2c67</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (if (= need-to-connect 1)
	      (progn
		;; 如果open-network-stream 出错, 就停止运行了, 后面的就得不到执行了. 如何解决???
		(setq  myproc (open-network-stream myproc-name nil host-address host-port))
		(set-process-filter myproc 'myfilter) ;;1
		(princ "11 connect to server ? \n");
		)
	    )
	  ;[F1olaQMHD8KDgigVvTSz] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf517b4a5a-7106-4471-8bea-0a5d9ea5f116</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (if myproc
	      (progn
		(if (> (length output-string) cmd-max-len)
		    (progn
		      (princ (format "不能向服务器发送命令, 命令太长了(大于 %d ) \n" cmd-max-len) )
		      )
		  (progn  
		    (princ "send... to server\n");
		    (process-send-string  myproc output-string)
		    (if (string=  set-curse-pos "head")
			(progn 
			  (goto-char (- start-id-pos 1))
			  )
		      (progn
			(if (string=  set-curse-pos "tail")
			    (progn
			      (goto-char (+ end-id-pos 0))
			      )
			  )
			)
		      )
		    
		    ;;(delete-process myproc) ;关闭连接
		   
		    )
		  )
		)
	    (progn
	      (princ "cannot connect to server\n");
	      )
	    )

	  
	  )

	)


      
      );let
    )
  )



		 ;; (if 1 
		 ;;     (progn
		;;	(setq start-id-pos (- start-id-pos start-id-len))
		;;	;;(setq end-id-pos (- end-id-pos end-id-len))
		;;	(setq result-string (buffer-substring-no-properties   start-id-pos end-id-pos))
		;;	(princ(format ">>>>result is: %s\n" result-string))
		;;	)
		;;    )
(defun some-fn (x)
  "   这个是用来测试用的, 因为elisp 没有 块注释 (block comment) 只能用这种方法了.             
(%%
<cmd-end/>
<cmd-start/>
<do-func>
<func-name>func__move_to_bookmark</func-name>
<func-param-1>简单的书签</func-param-1>
<func-param-2>./candev/plugin/emacs/简单介绍.can</func-param-2> 
</do-func>

<cmd-end/>    %%) 

(%%
<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfd6e34feb-4c0b-43f0-a2ca-da3114643f3a</func-param-1><func-param-2>./candev/plugin/emacs/debug/test3.can</func-param-2></do-func><cmd-end/>
 %%) 
Function: insert &rest args ¶
buffer-file-name

 "
  (setq x 1)
  ;;这个用来把 f12 定义为 jjump的快捷键
  ;;具体操作: 先 M-: ,  再输入这一行即可
  (global-set-key (kbd "<f12>") 'jjump )
  )


;[G5obe0P8Ety3F84XNPRK] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf61017eab-67c9-41f5-9b4d-3560e8b66099</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
(defun create-emacs-can-links()
  "--------"
  (interactive)
  
  ;(princ "1111\n");
  ;[hnoRvhT2VUEYfFgzGIXG] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfa4f36366-ddea-4f4a-999c-2b9d14f0dac8</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
  (setq rs (make-string random-string-length ?x))
  (setq num 0)
   (princ "2222\n");
  (while ( < num random-string-length)
    ;;(setq rs (concat rs (aref char-set (random (- char-set-len 1))) ) )
    (aset rs num  (aref char-set (random (- char-set-len 1))))
    ;;(princ "333\n");
    (setq num (+ num 1))
    )

  ;;(insert rs) ;ok
  ;;(insert buffer-file-name ) ; ok
  ;;(princ (format "%s\n"  buffer-file-name)) ; princ in message buffer


;[8ceqriSpnuGgcnSGve20] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfc0f0b426-9584-4536-8350-5e3d2a2da429</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
  (setq cur-file-type (get-file-type buffer-file-name))
  (princ (format "file type is %d" cur-file-type))
  (if (= cur-file-type valid-file-type)
      (progn
	(princ "same type, donot change\n")
	)
    (progn
      (princ (format "diff type, change from %d to %d\n" valid-file-type cur-file-type))
      (set-const-string-according-file-type cur-file-type);[8oeV1zNqxnICbAQaMtfV] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf660afaf5-6490-48ef-a777-3ff6c8e8d169</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
      (setq valid-file-type cur-file-type)
      
      )
    )

  
  (setq output-to-buffer ( concat part-a rs part-b))
  (insert output-to-buffer)
  ;[9mCKa2XvrLENewShcf3n] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf2b598399-0849-4b96-bab6-67f4c65c581a</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
  (insert " (%%")
  (insert " %%)")
  (backward-char  (length "%%)"))
  

  (setq output-string (concat part1 rs part2  (get-relative-filanme buffer-file-name) part3 part4 "c or cpp" part5 part6))
  ;;(princ output-string)

	  (setq need-to-connect 0)
	  (if myproc
	      (progn
		(setq myproc-status (process-status myproc));[p5gGtsorlWHfqNBM0E40] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf8e993a63-ba6d-4fe8-9a43-28c510456d10</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
		(princ (format "myproc status is :%s\n" myproc-status))
		(if (string= myproc-status "closed")
		    (progn
		      (setq need-to-connect 1)
		      )
		  )
		)
	    (progn
	      (setq need-to-connect 1)
	      )
	    )
	  ;[idF5s0otPCrgfu421LoH] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfdebd371b-2bab-4ab7-bf31-03a770843fb5</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (if (= need-to-connect 1)
	      (progn
		;; 如果open-network-stream 出错, 就停止运行了, 后面的就得不到执行了. 如何解决???
		(princ "2 connect to server ? \n");
		(setq  myproc (open-network-stream myproc-name nil host-address host-port));[GEIPEiYiStKgR9gg0zDg] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf483514f3-9031-4d9b-af33-abba35c73d11</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
		(set-process-filter myproc 'myfilter) ;;2
		(princ "22 connect to server ? \n");
		)
	    )
	  ;[mF2fgB0WSQiqrgBvNLvs] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf5d76e069-47f8-4b77-958f-67ab46e0c8ed</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (if myproc
	      (progn
		(if (> (length output-string) cmd-max-len)
		    (progn
		      (princ (format "不能向服务器发送命令, 命令太长了(大于 %d ) \n" cmd-max-len) )
		      )
		  (progn  
		    (princ "send... to server\n");
		    (princ(format "%s\n" output-string));
		    (process-send-string  myproc output-string)
		   
		    
		    ;;(delete-process myproc) ;关闭连接
		   
		    )
		  )
		)
	    (progn
	      (princ "cannot connect to server\n");
	      )
	    )
  )


;[UxQm4ruHaVmyTi5WX751] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfd717b121-22f4-4e49-a4b6-0b0c67f11b57</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
(defconst FILE-TYPE--UNKNOWN 0 "---")
(defconst FILE-TYPE--C-SERIES 1 "---")
(defconst FILE-TYPE--SHELL 2 "---")
(defconst FILE-TYPE--ELISP 3 "---")
(defconst FILE-TYPE--PYTHON 4 "---")


(setq valid-file-type FILE-TYPE--UNKNOWN)
;[BoghUqmS80ckauwal6U2] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfcf7c3ea4-37a0-43c8-a990-3d351e4cbced</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
(defun get-file-type( filename)
  "--------"
  (catch 'break
  (while t
    (if (string-suffix-p ".c" filename t)
	(progn
	  (throw 'break FILE-TYPE--C-SERIES)
	  )
      )
    (if (string-suffix-p ".cc" filename t)
	(progn
	  (throw 'break FILE-TYPE--C-SERIES)
	  )
      )
    (if (string-suffix-p ".cpp" filename t)
	(progn
	  (throw 'break FILE-TYPE--C-SERIES)
	  )
      )    
    (if (string-suffix-p ".h" filename t)
	(progn
	  (throw 'break FILE-TYPE--C-SERIES)
	  )
      )
     (if (string-suffix-p ".hh" filename t)
	(progn
	  (throw 'break FILE-TYPE--C-SERIES)
	  )
       )  
     (if (string-suffix-p ".ts" filename t)
	(progn
	  (throw 'break FILE-TYPE--C-SERIES)
	  )
       )
      (if (string-suffix-p ".json" filename t)
	(progn
	  (throw 'break FILE-TYPE--C-SERIES)
	  )
       )
        
     (if (string-suffix-p ".el" filename t)
	 (progn
	   (princ ".el")
	   (throw 'break FILE-TYPE--ELISP)
	     (princ "--.el")
	  )
       )
     (if (string-suffix-p ".sh" filename t)
	(progn
	  (throw 'break FILE-TYPE--SHELL)
	  )
       )
     (if (string-suffix-p ".py" filename t)
	 (progn
	   (throw 'break FILE-TYPE--PYTHON)
	   )
       )
    (throw 'break FILE-TYPE--UNKNOWN)
    )
  )
  )
;[BWdsfAriNIhYvd6QS4cb] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf03e1c2aa-0f2b-4e66-9122-0e282e9432bd</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
(defun set-const-string-according-file-type( filetype)
  "---"
  (setq valid-file-type filetype)
  (catch 'break
  (while t
    (if (= filetype FILE-TYPE--UNKNOWN)
	(progn;[V9xUCiGlpDORrGI7bXLO] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf8f4c6a10-eb01-4e23-a377-4e6771ea5720</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (setq part-a "[")
	  (setq part-b "]")
	  
	  (throw 'break nil)
	  )
      )   
    (if (= filetype FILE-TYPE--C-SERIES)
	(progn;[GrSoiPpCXdUOFgDSk1Vk] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfa8831749-9f07-4b44-acf7-4c2cc46471bb</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (setq part-a "//[")
	  (setq part-b "]")
	  (throw 'break nil)
	  )
      )
    (if (= filetype FILE-TYPE--SHELL)
	(progn;[cOF1xaksDHo5gA03kPBD] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf5b3134cc-52d9-435a-b8da-77908d8f12f3</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (setq part-a "#[")
	  (setq part-b "]")
	  (throw 'break nil)
	  )
      )
    (if (= filetype FILE-TYPE--ELISP)
	(progn;[usgngUY1DoddVGaWlESQ] (%% //<cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasfe690b467-26ee-4401-97db-04f29b5664cc</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (setq part-a ";[")
	  (setq part-b "]")
	  (throw 'break nil)
	  )
      )
    (if (= filetype FILE-TYPE--PYTHON)
	(progn;[oWodhF0pgH4hKrkfEmNE] (%% <cmd-end/><cmd-start/><do-func><func-name>func__move_to_item</func-name><func-param-1>asfasf53ce2a81-bf74-49cb-88c1-7fb4a9dd0171</func-param-1><func-param-2>./candev/plugin/emacs/emacs插件流程图.can</func-param-2></do-func><cmd-end/>%%)
	  (setq part-a "#[")
	  (setq part-b "]")
	  (throw 'break nil)
	  )
      )
    (throw 'break nil)
    )
  )

  )

(defun get-relative-filanme( filename)
  "----"
  (catch 'return
    (if (string-prefix-p relative-path-1  filename)
	(progn
	  (setq rela (concat "./"   (substring filename relative-path-1-len nil)))
	  (throw 'return rela)
	  )
      )
    (if (string-prefix-p relative-path-2  filename)
	(progn
	  (setq rela (concat "./"   (substring filename relative-path-2-len nil)))
	  (throw 'return rela)
	  )
      )    
    (throw 'return filename)
    )

  )



(defun set-root-path-for-file-location( the-path)
  (setq  root-path the-path) 
  )



(defun jjump-file-src ()
  "-----"
  (interactive);

  (setq line-head-pos (line-beginning-position))
  (setq line-end-pos (line-end-position))
  ; This function does not move point across a field boundary (see Defining and Using Fields) unless doing so would move beyond there to a different line; therefore, if count is nil or 1, and point starts at a field boundary, point does not move. To ignore field boundaries, bind inhibit-field-text-motion to t. 
  ;(end-of-line) ;normally same as (goto-char line-end-pos) 
  (goto-char line-end-pos) 
  (setq filename-begin  (re-search-backward "[< ]" line-head-pos)) ;
  (setq filename-end  (search-forward ":" line-end-pos)) ;
  (setq line-num-end  (re-search-forward "[> ]\\|[0123456789]$" line-end-pos)) ;

  (setq cur-char (string (following-char)))
  ;(princ  "123\n")
  (if (string= cur-char " ")
      (progn
	)
     (progn
       
       (if (string= cur-char ">")
	   (progn
	     )
	 (progn
	   (setq line-num-end ( + line-num-end 1))
	   )
	 )
       )
     )
    
  
  ;(princ line-head-pos)   (princ  "\n")
  ;(princ line-end-pos)   (princ "\n")
  ;(princ filename-begin)   (princ "\n")
  ;(princ filename-end)   (princ "\n")
  ;(princ line-num-end)   (princ "\n")

  (setq filename (buffer-substring-no-properties (+ 1 filename-begin) (- filename-end 1)))
  (setq line-num (buffer-substring-no-properties filename-end (- line-num-end 1)))
  (princ filename)   (princ  "\n")
  (princ line-num)   (princ "\n");
  (princ relative-path-1)  (princ "\n");
				
  (setq full-filename ( directory-files-recursively relative-path-1   (concat "" (regexp-quote filename) "$" )));
  (setq found 0)
  (if (booleanp  full-filename)
      (progn
	(setq found 1)
	(setq full-filename  (concat relative-path-1 filename))
	)
    )
  
  (princ full-filename)   (princ  "||--11\n")
  (if (= found 0)
      (progn
	(find-file (car full-filename))
	)
    (progn ; else
      (find-file full-filename)
      )
    )
  (princ  "---||--\n")
  (princ line-num);
  ;(beginning-of-buffer) no effect
  ;(forward-line -10000000) ;ok
  (goto-char (point-min))
  (forward-line (string-to-number line-num));
  ;(forward-line 1000);
  (princ  "---||--\n")
  )
